#include <iostream>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>
void handler(int a){
    std::cout << "Received signal: " << a << std::endl;
}
int main(){
    signal(2, handler);
    pid_t pid = fork();
    if (pid == 0) {
        int cnt = 0;
        // alarm(2);
        while (cnt < 2){
            std::cout << "Waiting for signal" << std::endl;
            cnt++;
            sleep(1);
        }
        int t = 2 / 0;
    }
    int status;
    waitpid(pid,&status,0);
    std::cout<<((status>>7)&1)<<std::endl;
    // raise(9);
    return 0;
}